package com.demo.Test;

import com.demo.Model.User;

import java.sql.*;

public class Test5 {

    public static void main(String[] args)throws ClassNotFoundException, SQLException {
        String url= "jdbc:mysql://106.13.7.203:3306/wg12?useCursorFetch=true&amp;autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=UTF-8";
        String username = "root";
        String password = "Asd6250390@";
        Class.forName("com.mysql.jdbc.Driver");
        Connection conn = DriverManager.getConnection(url, username, password);
        System.out.println("连接成功");

        Statement st = conn.createStatement();
        String sql = "select * from users";
        ResultSet rs = st.executeQuery(sql);
        User[] user = new User[5];
        int i=0;
        while(rs.next()){
            User user1 = new User();
            user1.setId(rs.getInt("id"));
            user1.setName(rs.getString("name"));
            user1.setGender(rs.getString("gender"));
            user1.setAge(rs.getInt("age"));
            user[i] = user1;
            i++;
        }
        System.out.println(user);
    }
}
